package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Collection;
import com.mall.db.service.CollectionService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system/col")
public class CollectionController extends BaseController<Collection>{

    @Resource(name = "collectionService")
    private CollectionService cos;

    @Override
    public Map<String, Object> find(Collection collection) {
        PageHelper.startPage(collection.getPage(),collection.getLimit());
        QueryWrapper qw=new QueryWrapper();
        if(!StringUtils.isEmpty(collection.getUserNameId()))
            qw.eq("user_name_id",collection.getUserNameId());
        if(!StringUtils.isEmpty(collection.getComNameId()))
            qw.eq("com_name_id",collection.getComNameId());
        List<Collection> list= cos.list(qw);
        PageInfo<Collection> pageInfo=new PageInfo<>(list,collection.getLimit());
        return this.findMap(pageInfo.getList(),pageInfo.getTotal());
    }

    @Override
    public Map<String, Object> add(Collection collection) {

        boolean b= cos.save(collection);
        return this.iud("收藏",b,collection);
    }
}
